#include "dsp_test.h"

#include "arm_math.h"
#include "system_tick.h"

#define RETRY_COUNT 100000

extern int32_t arm_matrix_main(void);
extern int32_t arm_bayes_main(void);
extern int32_t class_marks_main();
extern int32_t arm_fft_bin_main(void);
extern int32_t arm_fir_main(void);
extern int32_t graphic_equalizer_main(void);
extern int32_t arm_svm_main(void);
extern int32_t arm_linear_interp_main(void);
extern int32_t arm_variance_main(void);
extern int32_t arm_sin_cos_main(void);
extern int32_t arm_signal_converge_main(void);
extern int32_t arm_dotproduct_main(void);
extern int32_t arm_convolution_main(void);

struct dsp_test_t {
  int32_t (*func)(void);
  char *name;
  unsigned long retry;
};

struct dsp_test_t dsp_test[] = {
    {arm_bayes_main, "arm_bayes_main", 100000},
    {arm_convolution_main, "arm_convolution_main", 10000},
    {arm_dotproduct_main, "arm_dotproduct_main", 200000},
    {arm_fft_bin_main, "arm_fft_bin_main", 2500},
    {arm_fir_main, "arm_fir_main", 5000},
    {arm_linear_interp_main, "arm_linear_interp_main", 200000},
    {arm_matrix_main, "arm_matrix_main", 100000},
    {arm_signal_converge_main, "arm_signal_converge_main", 200},
    {arm_sin_cos_main, "arm_sin_cos_main", 50000},
    {arm_svm_main, "arm_svm_main", 300000},
    {arm_variance_main, "arm_variance_main", 300000},
    {class_marks_main, "class_marks_main", 200000},
    {graphic_equalizer_main, "graphic_equalizer_main", 2500},
};

void dsp_test_func(void) {
  unsigned long i;
  unsigned int j;
  TIMING_FORMAT tick_start = 0, tick_end = 0;

#if defined(ARM_MATH_MVEF) || defined(ARM_MATH_MVEI)
  printf("Helium version\n\r");
#else
  printf("Normal version\n\r");
#endif

  for (j = 0; j < sizeof(dsp_test) / sizeof(struct dsp_test_t); j++) {
    tick_start = systick_get();
    for (i = 0; i < dsp_test[j].retry; i++) {
      dsp_test[j].func();
    }
    tick_end = systick_get();
    printf("%s use: %ums\n\r", dsp_test[j].name, tick_end - tick_start);
  }
  printf("test done\n\r");

  while (1) {
    ;
  }
}